package mspbots.autotask.client.core.data.users;

import com.fasterxml.jackson.databind.JsonNode;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import mspbots.autotask.common.QueryBody;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import javax.validation.Valid;
import java.net.URI;

/**
 * mspbots.core.autotask.core.users.UsersController
 *
 * @author <a href="https://github.com/vnobo">Alex bob</a>
 * @date Created by 2020/7/22
 */
@Log4j2
@RestController
@RequestMapping("users/{tenantId}")
@RequiredArgsConstructor
public class UsersController {

    private final UsersServiceImpl usersService;

    @PostMapping("find")
    public Mono<JsonNode> findUsers(@PathVariable Long tenantId,
                                    @Valid @RequestBody QueryBody queryBody,
                                    @RequestParam(required = false) URI pageUrl) {
        return this.usersService.find(tenantId, queryBody, pageUrl);
    }

    @PostMapping("count")
    public Mono<JsonNode> countUsers(@PathVariable Long tenantId,
                                     @Valid @RequestBody QueryBody queryBody) {
        return this.usersService.count(tenantId, queryBody);
    }

}
